package com.yxch.admin.controller;

import com.yxch.admin.utils.AliOSSUtils;
import com.yxch.admin.utils.ResultAPI;
import com.yxch.admin.utils.Upload;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@RestController
@Slf4j
@RequestMapping("/yxch/admin/upload")
public class UploadController {
    @Autowired
    AliOSSUtils aliOSSUtils;

    @PostMapping
    public ResultAPI upload(@RequestParam("file") MultipartFile file) {
        String url = null;
        try {
            url = aliOSSUtils.upload(file);
        } catch (IOException e) {
            return ResultAPI.error("文件上传失败！");
        }
//        String url = Upload.upload(file);
        return ResultAPI.success(url);
    }
}
